#!/bin/bash
. config
createrepo()
{

mkdir $wdir/"$fname"workingdir
echo "This will Create a repository on a host and make a working directory for you on your own machine."
ssh $username@$hostip "cd $path && mkdir "$fname"repo && cd "$fname"repo && svnadmin create $fname && mkdir $wdir/"$fname"workingdir"
unzip $wordfilepath/$fname.odt -d $wdir/"$fname"workingdir
ssh $username@$hostip "cd $path/"$fname"repo/ && mkdir $path/temp && svn import $path/temp/ file:///$path/"$fname"repo/$fname/trunk -m "FI" && rmdir $path/temp "
}
checkout()
{
cd $wdir/"$fname"workingdir
svn co svn+ssh://$username@$hostip/$path/"$fname"repo/$fname/trunk $wdir/"$fname"workingdir/
svn update   
echo "your File under version control is $fname.odt  Do not move this file from this Location. \nRun this script again with appropriate arguments to commit and update your work"
ooffice $wordfilepath/$fname.odt
}

update()
{
cd $wdir/"$fname"workingdir/
svn update
zip -r $wordfilepath/$fname.zip .
mv $wordfilepath/$fname.zip $wordfilepath/$fname.odt
cd -				
																			
}
commit()
{
unzip $wordfilepath/$fname.odt -d $wdir/"$fname"workingdir
cd $wdir/"$fname"workingdir/
svn add * > /dev/null
svn commit
}
difference()
{
cd $path/"$fname"workingdir/
svn diff
}

option=$1
echo "Please be patient if this script halts in Between. since you are handling files on a network, the processing depends on your connection speed.\nYou may be prompted to enter passwords whenever required."
if [ $option == create ]
then
createrepo;
fi

if [ $option == update ]
then
update;
fi

if [ $option == commit ]
then
commit;
fi

if [ $option == dif ]
then
difference;
fi

if [ $option == checkout ]
then
checkout;
fi
